<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打字机效果</title>
    <style>
        :root{
            --typeSpeed:4s;
            --strLength:16;
            --bg-color:#454545;
            --font-color:#fff;
        }
        *{
            padding: 0;
            margin: 0;
        }
        body{
            display: flex;
            height: 100vh;
            justify-content: center;
            align-items: center;
            background-color: var(--bg-color);
            color: var(--font-color);
        }
        h1{
            position: relative;
        }
        h1:before,h1:after{
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }
        h1:before{
            background-color: var(--bg-color);
            animation: typing var(--typeSpeed) steps(var(--strLength)) 1s forwards;
        }
        h1:after{
            width: 2px;
            background-color: var(--bg-color);
            animation: 
                typing var(--typeSpeed) steps(var(--strLength)) 1s forwards,
                blink 500ms var(--typeSpeed) steps(var(--strLength)) infinite;
        }
        @keyframes typing {
            from{
                left: 0;
            }
            to{
                left: 100%;
            }
        }
        @keyframes blink {
            0% , 100%{
                background: transparent;
            }
            50%{
                background: #fff;
            }
        }
    </style>
</head>
<body>
    <h1 class="heading">Coding is funny！</h1>
</body>
</html>